<template>
	<view class="confirmOrder">
		<view class="serveMessage">
			<view class="titleBox">
				<view class="shu"></view>
				<view class="">
					服务信息
				</view>
			</view>
			<view class="serveitem">
				<image :src="servedData.image" style="width: 144rpx;height: 144rpx;border-radius: 10rpx;" mode="">
				</image>
				<view class="servemessage">
					<view class="name">
						{{servedData.sname}}
					</view>
					<view class="desc">
						{{servedData.introduction}}
					</view>
				</view>
				<view class="price">
					￥{{servedData.price}}
				</view>
			</view>
		</view>

		<view v-if="servedData.stype==1" class="serveMessage" style="margin-top: 20rpx;">
			<view class="titleBox">
				<view class="shu"></view>
				<view class="">
					鸽子信息
				</view>
			</view>
			<view class="inoutBox">
				<view class="lable">
					环号
				</view>
				<input class="inputItem" v-model="ring" type="text" placeholder="请输入" />
			</view>
			<view class="inoutBox">
				<view class="lable">
					羽色
				</view>
				<input class="inputItem" v-model="color" type="text" placeholder="请输入" />
			</view>
		</view>

		<view v-if="servedData.stype==1" class="serveMessage" style="margin-top: 20rpx;">
			<view class="titleBox">
				<view class="shu"></view>
				<view class="">
					服务流程
				</view>
			</view>

			<view class="flowBox">
				<image :src="imaurl+'c4.png'" style="width: 32rpx;height: 242rpx;" mode=""></image>
				<view class="flowList">
					<view class="flowItem">
						<text class="number">01</text>
						<text>提交订单并成功支付</text>
					</view>
					<view class="flowItem">
						<text class="number">02</text>
						<text>将相关送检物品寄送到官方地址</text>
					</view>
					<view class="flowItem">
						<text class="number">03</text>
						<text>官方收件后开始为您检测</text>
					</view>
					<view class="flowItem">
						<text class="number">04</text>
						<text>检测完成后上传相关报告，服务结束</text>
					</view>
				</view>
			</view>
		</view>


		<view class="serveMessage" style="margin-top: 20rpx;">
			<view class="titleBox">
				<view class="shu"></view>
				<view class="">
					支付方式
				</view>
			</view>

			<view class="payType">
				<image :src="imaurl+'wxpay.png'" style="width: 48rpx;height: 48rpx;" mode=""></image>
				<view class="" style="margin-left: 20rpx;">
					微信支付
				</view>
				<image :src="imaurl+'fill.png'" style="width: 40rpx;height: 40rpx;margin-left: 404rpx;" mode=""></image>
			</view>
		</view>

		<view class="" style="height: 200rpx;"></view>

		<view class="bottomBtn">
			<view v-if="servedData.is_vip==1"  class="left">
				<view class="price">
					￥0.00
				</view>
				<view class="text">
					您是尊贵的会员，可以免费使用该服务
				</view>
			</view>
			<view v-else  class="left">
				<view class="price">
					￥{{servedData.price}}
				</view>
				<view class="text">
					<!-- 您是尊贵的会员，可以免费使用该服务 -->
				</view>
			</view>
			<view class="btns" @click="handleBuy">
				立即支付
			</view>
		</view>

	</view>
</template>

<script>
	import {
		serviceinfo,
		submitservice
	} from "@/api/api.js"
	export default {
		data() {
			return {
				serveId: "",
				servedData: {},
				ring: "",
				color: "",
				imaurl: "https://szgb.tongchengbang.cc/img/image/",
			}
		},
		onLoad(options) {
			console.log("options", options)
			this.serveId = options.id
			this.handleserviceinfo()
		},
		methods: {
			async handleserviceinfo() {
				let res = await serviceinfo({
					id: this.serveId
				})
				this.servedData = res.data
			},
			async handleBuy() {
				if(this.servedData.stype==1){
					if (this.ring == "") {
						uni.showToast({
							title: "请输入环号",
							icon: "none",
							duration: 2000
						});
						return
					}
					if (this.color == "") {
						uni.showToast({
							title: "请输入羽色",
							icon: "none",
							duration: 2000
						});
						return
					}
				}
				
				let data = {
					sid: this.serveId,
					ring: this.ring,
					color: this.color
				}
				// console.log("data", data)
				let res = await submitservice(data)
				if (res.code == 1) {
					if (res.data.is_fee == 0) {
						uni.requestPayment({
							provider: 'wxpay',
							appId: res.data.wechat_pay_data.appId,
							timeStamp: res.data.wechat_pay_data.timeStamp,
							nonceStr: res.data.wechat_pay_data.nonceStr,
							package: res.data.wechat_pay_data.package,
							signType: res.data.wechat_pay_data.signType,
							paySign: res.data.wechat_pay_data.paySign,
							success(ress) {
								console.log("支付成功、、、、、、、、、、、、、、、、")
								// uni.showToast({
								// 	title: ress.msg,
								// 	icon: "none",
								// 	duration: 2000
								// });
								setTimeout(() => {
									uni.redirectTo({
										url: "./orderSuccessful"
									})
								}, 1900)
							},
							fail(e) {}
						})

					} else {
						uni.showToast({
							title: res.msg,
							icon: "none",
							duration: 1800
						});
						setTimeout(() => {
							uni.redirectTo({
								url: "./orderSuccessful"
							})
						}, 1900)
					}

				} else {
					uni.showToast({
						title: res.msg,
						icon: "none",
						duration: 1800
					});
				}

			},
		}
	}
</script>

<style scoped lang="scss">
	.bottomBtn {
		width: 100%;
		background: #ffffff;
		position: fixed;
		bottom: 0;
		padding: 16rpx 30rpx;
		box-sizing: border-box;
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding-bottom: constant(safe-area-inset-bottom);
		/* 兼容 iOS 设备 */
		padding-bottom: env(safe-area-inset-bottom);

		.left {
			.text {
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				font-size: 24rpx;
				color: #E8A700;
				line-height: 28rpx;
			}

			.price {
				font-family: DIN, DIN;
				font-weight: 600;
				font-size: 32rpx;
				color: #E40700;
				line-height: 38rpx;
			}
		}

		.btns {
			width: 240rpx;
			height: 84rpx;
			background: #00BF52;
			border-radius: 200rpx 200rpx 200rpx 200rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 400;
			font-size: 32rpx;
			color: #FFFFFF;
			line-height: 84rpx;
			text-align: center;
		}
	}

	.confirmOrder {
		.titleBox {
			font-family: PingFang SC, PingFang SC;
			font-weight: 800;
			font-size: 32rpx;
			color: #333333;
			line-height: 38rpx;
			display: flex;
			align-items: center;

			.shu {
				width: 8rpx;
				height: 32rpx;
				background: #00BF52;
				border-radius: 200rpx 200rpx 200rpx 200rpx;
				margin-right: 20rpx;
			}
		}

		.serveMessage {
			width: 750rpx;
			// height: 318rpx;
			background: #FFFFFF;
			margin-top: 1rpx;
			padding: 30rpx 30rpx;
			box-sizing: border-box;

			.serveitem {
				display: flex;
				align-content: center;
				align-items: center;
				width: 690rpx;
				height: 184rpx;
				background: #F6F6F6;
				border-radius: 20rpx 20rpx 20rpx 20rpx;
				padding: 20rpx;
				box-sizing: border-box;
				// margin-bottom: 20rpx;
				margin-top: 30rpx;

				.servemessage {
					flex: 1;
					margin-left: 20rpx;
					height: 144rpx;
					display: flex;
					flex-direction: column;
					justify-content: space-between;

					.name {
						font-family: PingFang SC, PingFang SC;
						font-weight: 400;
						font-size: 32rpx;
						color: #333333;
						line-height: 38rpx;
					}

					.desc {
						width: 340rpx;
						height: 80rpx;
						font-family: PingFang SC, PingFang SC;
						font-weight: 400;
						font-size: 28rpx;
						color: #999999;
						line-height: 33rpx;
					}
				}

				.price {
					font-family: DIN, DIN;
					font-weight: 500;
					font-size: 36rpx;
					color: #E40700;
					line-height: 42rpx;
					// margin-left: 30rpx;
				}
			}

			.inoutBox {
				display: flex;
				align-items: center;
				margin-top: 30rpx;

				.lable {
					font-family: PingFang SC, PingFang SC;
					font-weight: 400;
					font-size: 28rpx;
					color: #333333;
					line-height: 33rpx;
				}

				.inputItem {
					width: 614rpx;
					height: 80rpx;
					background: #F6F6F6;
					border-radius: 20rpx 20rpx 20rpx 20rpx;
					font-family: PingFang SC, PingFang SC;
					font-weight: 400;
					font-size: 28rpx;
					// color: #999999;
					line-height: 33rpx;
					padding-left: 30rpx;
					box-sizing: border-box;
					margin-left: 20rpx;
				}
			}

			.flowBox {
				margin-top: 34rpx;
				display: flex;
				align-items: center;

				.flowList {
					height: 242rpx;
					display: flex;
					flex-direction: column;
					justify-content: space-between;
					margin-left: 30rpx;

					.flowItem {
						font-family: PingFang SC, PingFang SC;
						font-weight: 400;
						font-size: 28rpx;
						color: #666666;
						line-height: 33rpx;

						.number {
							font-family: DIN, DIN;
							font-weight: 600;
							font-size: 32rpx;
							color: #00BF52;
							line-height: 38rpx;
							margin-right: 20rpx;
						}
					}
				}

			}

			.payType {
				width: 688rpx;
				height: 98rpx;
				border-radius: 0rpx 0rpx 0rpx 0rpx;
				border: 2rpx solid #00BF52;
				display: flex;
				align-items: center;
				padding: 30rpx;
				box-sizing: border-box;
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				font-size: 24rpx;
				color: #333333;
				line-height: 28rpx;
				margin-top: 30rpx;
			}
		}
	}
</style>